#include "Version.h"

#include "StrUtils.h"

Version::Version(void):m_version("1.0")
{
	getVersionId();
}


Version::~Version(void)
{
}

void Version::setVersion( const std::string &ver )
{
	m_version = ver;
	getVersionId();
}

std::string Version::getVersion() const
{
	return m_version;
}

int Version::getMainVerId()
{
	return m_mainVerId;
}

int Version::getSubVerId()
{
	return m_subVerId;
}

bool Version::compare( Version &otherVersion )
{
	if (m_mainVerId > otherVersion.getMainVerId()) {
		return true;
	}else if (m_mainVerId == otherVersion.getMainVerId()) {
		if (m_subVerId > otherVersion.getSubVerId()) {
			return true;
		}
	}
	return false;
}

/************************************************************************/
/* private                                                              
*/
void Version::getVersionId()
{
	std::vector<std::string> verIds = StrUtils::strSplit(m_version, '.');
	if (verIds.size() >= 2) {
		m_mainVerId = StrUtils::toInt(verIds.at(0));
		m_subVerId = StrUtils::toInt(verIds.at(1));
	}else if(verIds.size() == 1){
		m_mainVerId = StrUtils::toInt(verIds.at(0));
		m_subVerId = 0;
	}else{
		m_mainVerId = 0;
		m_subVerId = 0;
	}
}
/************************************************************************/
